package com.lr.springbootdemo.controller;

import com.lr.springbootdemo.bean.People;
import com.lr.springbootdemo.service.DemoService;
import com.lr.springbootdemo.util.JsonUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * .
 * Created by li.rui on 2016-06-12.
 */
@Controller
@RequestMapping("/")
public class DemoController{
    private static Logger logger = LoggerFactory.getLogger(DemoController.class);
    @Resource
    private DemoService demoService;

    @RequestMapping("/")
    public String test(Model model,HttpServletRequest request){
        request.getSession().setAttribute("session","session2222222222222");
        logger.info(request.getSession().getAttribute("session").toString());

        logger.info(JsonUtil.object2String(demoService.getList()));
        System.out.println(111111111);
        int i =0 ;
        StringBuilder sb = new StringBuilder();
        while (i<10){
            sb.append("是深深深是是是是是是是是是是是是所所是深</br>");
            i++;
        }
        model.addAttribute("text",sb.toString());
//        return JsonUtil.object2String(demoService.getList());
        return "index";
    }

    @RequestMapping("testRepository")
    public Object testRepository(){
        People people = new People();
        people.setId(1);
        people.setAge(2);
        people.setName("xiaoming");
        people.setSex("man");
        demoService.testRepository(people);
        return "ok";
    }

}
